package com.zenithmind.chat.pojo.vo;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.time.LocalDateTime;
import java.util.List;

/**
 * AI对话详情VO
 * 遵循单一职责原则，专门用于展示对话详细信息
 */
@Data
@EqualsAndHashCode(callSuper = true)
@Schema(description = "AI对话详情VO")
public class AiChatDetailVO extends BaseVO {
    
    @Schema(description = "用户ID")
    private String userId;
    
    @Schema(description = "用户名称")
    private String userName;
    
    @Schema(description = "对话标题")
    private String title;
    
    @Schema(description = "模型类型(1-OpenAI,2-Ollama,3-Azure,4-Anthropic,5-自定义)")
    private Integer modelType;
    
    @Schema(description = "模型类型名称")
    private String modelTypeName;
    
    @Schema(description = "模型名称")
    private String modelName;
    
    @Schema(description = "系统提示词")
    private String systemPrompt;
    
    @Schema(description = "状态(0-禁用,1-启用)")
    private Integer status;
    
    @Schema(description = "状态名称")
    private String statusName;
    
    @Schema(description = "总token数")
    private Integer totalTokens;
    
    @Schema(description = "最后对话时间")
    private LocalDateTime lastChatTime;
    
    @Schema(description = "对话次数")
    private Integer chatCount;
    
    @Schema(description = "是否收藏")
    private Boolean isFavorite;
    
    @Schema(description = "是否置顶")
    private Boolean isTop;
    
    @Schema(description = "共享类型(0-私有,1-公开,2-指定用户)")
    private Integer shareType;
    
    @Schema(description = "共享类型名称")
    private String shareTypeName;
    
    @Schema(description = "标签列表")
    private List<AiChatTagVO> tags;
    
    @Schema(description = "最近消息列表")
    private List<AiChatMessageVO> recentMessages;
    
    @Schema(description = "统计信息")
    private AiChatStatisticsVO statistics;
    
    @Override
    public String getDisplayName() {
        return title;
    }
    
    @Override
    public String getStatusDescription() {
        if (status == null) {
            return "未知";
        }
        return status == 1 ? "启用" : "禁用";
    }
    
    /**
     * 获取模型类型名称
     */
    public String getModelTypeName() {
        if (modelType == null) {
            return "未知";
        }
        return switch (modelType) {
            case 1 -> "OpenAI";
            case 2 -> "Ollama";
            case 3 -> "Azure";
            case 4 -> "Anthropic";
            case 5 -> "自定义";
            default -> "未知";
        };
    }
    
    /**
     * 获取共享类型名称
     */
    public String getShareTypeName() {
        if (shareType == null) {
            return "私有";
        }
        return switch (shareType) {
            case 0 -> "私有";
            case 1 -> "公开";
            case 2 -> "指定用户";
            default -> "私有";
        };
    }
    
    /**
     * 获取格式化的token数量
     */
    public String getFormattedTokens() {
        if (totalTokens == null || totalTokens == 0) {
            return "0";
        }
        if (totalTokens >= 1000000) {
            return String.format("%.1fM", totalTokens / 1000000.0);
        } else if (totalTokens >= 1000) {
            return String.format("%.1fK", totalTokens / 1000.0);
        }
        return totalTokens.toString();
    }
}
